﻿namespace JunFan.Tests.UnitTests
{
    using System;
    using FluentAssertions;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Infrastructure;

    [TestClass]
    public class CalculatingLeadTime
    {
        /// <summary>
        /// Given: A completed item
        /// When: Calculating lead time
        /// Then: Lead time equals completed date - created date (in days)
        /// </summary>
        [TestMethod]
        public void ShouldBeCompletedDateMinusCreatedDateInDays()
        {
            var completedItem = Given.CompletedItem.Build();

            // When
            int leadTime = completedItem.LeadTime;

            // Then
            leadTime.Should().Be((completedItem.CompletedOn.Value - completedItem.CreatedOn).Days);
        }

        /// <summary>
        /// Given: A not completed item
        /// When: Calculating lead time
        /// Then: Lead time equals Today - created date (in days)
        /// </summary>
        [TestMethod]
        public void ShouldBeTodayMinusCreatedDateWhenItemIsIncomplete()
        {
            var notCompletedItem = Given.NewItem
                                        .CreatedOn(DateTime.Today.AddDays(-40))
                                        .Build();

            // When
            int leadTime = notCompletedItem.LeadTime;

            // Then
            leadTime.Should().Be((DateTime.Today - notCompletedItem.CreatedOn).Days);
        }
    }
}
